package com.qi.demo1.test0127;


import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;

@RestController
@RequestMapping("/talk")
public class T {
    private ArrayList<Talk> list = new ArrayList<>();

      @RequestMapping(value = "/r1", produces = "application/json")
    public String publish(@RequestBody Talk talk) {
        if (!StringUtils.hasLength(talk.getFrom()) ||
                !StringUtils.hasLength(talk.getTalk()) || !StringUtils.hasLength(talk.getTo())) {
            return "{\"ok\": 0}";
        } else {
            list.add(talk);
            return "{\"ok\": 1}";

        }
    }



    @RequestMapping(value = "/r2" )
    public ArrayList<Talk> getList(){
          return list;
    }
}
